package com.heba.utils;

import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.graphics.ColorUtils;

import com.heba.greenmulu.GuideActivity;
import com.heba.greenmulu.R;
import com.heba.greenmulu.login.LoginActivity;
import com.heba.greenmulu.login.PasswordForgetActivity;
import com.heba.greenmulu.login.SignUpCompleteActivity;
import com.heba.greenmulu.login.SignUpNewActivity;

import java.lang.reflect.Field;

/**
 * 状态栏处理工具类
 * Created by jason on 2019/3/26.
 */
public class StatusBarUtils {

    /**
     * 设置状态栏透明
     * To change status bar to transparent.
     *
     * @notice this method have to be used before setContentView.
     */
    public static void setStatusBar(Context context) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window =  ((Activity) context).getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
            window.setNavigationBarColor(Color.TRANSPARENT);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window =  ((Activity) context).getWindow();
            window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }

    /**
     * 获取statusBar高度
     *
     * @return height of status bar
     */
    public static int getStatusBarHeight(Context context) {
        int result = 0;
        int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = context.getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }
    public static void setStatusLightMode(Context context){
        int currentNightMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
        Window window = ((Activity) context).getWindow();
        if (currentNightMode == 32){
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.BLACK);
            //日间 切换 夜间

        }else{
            if ((((Activity)context) instanceof GuideActivity)||(((Activity)context) instanceof LoginActivity)
            ||(((Activity)context) instanceof PasswordForgetActivity)||(((Activity)context) instanceof SignUpNewActivity)||
                    (((Activity)context) instanceof SignUpCompleteActivity)){

            }else {
                window.setStatusBarColor(context.getResources().getColor(R.color.colorGreen, null));
            }

        }



    }

}
